GBML manual / Drawing

Depth groups - layers of drawing

Name layers of drawing in the Room Editor tab - ground, things, sky - and a whole layer is always drawn over the one before it. Inside a layer, things sort by depth or by how far down the screen they are.

Layers you can name

Without depth groups, every picture in the game is sorted by one number, its depth. That works, but it is one big pile: the floor decorations, the characters, the clouds and the HUD frame all fight over the same numbers.

A depth group is a named layer of drawing. You make a few of them, put them in order, and say which group each object lives in. A whole group is always drawn over the groups before it, whatever the depth of anything inside either one.

Group (back to front)What lives in it
groundpuddles, shadows, floor decorations
thingsthe player, enemies, crates, trees
skyclouds, a bird flying over everything

A shadow in ground can never be drawn over the player in things, even if you give the shadow a depth that looks "closer". The group decides first.

A project with no groups is drawn exactly as it always was. Groups are something you add when you want them.

Making groups

Open the Room Editor tab. The Depth groups section in the right-hand panel lists the groups, back first.

Each group has three choices:

ChoiceWhat it does
Sort by yInside this group, things lower on the screen are drawn over things higher up. This is the look of a top-down game: walk behind a tree and it covers you, walk in front and you cover it. With it off, things are ordered by their depth.
Steps ofWith Sort by y: the height, in pixels, of the steps the y position is rounded to. Two things in the same step keep the same order, so they do not flicker over each other when they stand side by side. 16 is a good start.
Behind the backgroundThe whole group is drawn behind the room's picture - its tiles. Use it for something seen through a gap in the floor, such as water under a bridge.

A project can have up to 16 groups.

Putting things in groups

There are three places, from the whole object down to one copy:

  1. The object. Open the object in the Code tab. The Depth group list under Palette chooses the group every new copy of it starts in. Leave it on the first group and the object has no choice of its own.
  2. One copy in a room. Right-click it in the Room Editor and pick Depth group. The list of your groups opens inside the menu. The object's group puts the copy back with its object. The menu names the group when a copy has its own.
  3. Anything with no choice at all is in the first group.

Things worth knowing

See also: Drawing and the draw orderdepthbg_priorityBudgets